package data;

import java.util.ArrayList;

/**
 * Sorts objects.
 * @author Frans Honig, Maxime Serrano, Raphael Townshend
 * @param <T> The object that will be sorted.
 */
public class Sorter<T extends DateComparable<T>>
{
	/**
	 * Sorts the list by date.
	 * @param list The list to be sorted.
	 */
	public void dateSort(T[] list)
	{
		for (int i = 0; i < list.length; i++)
		{
			for (int j = 0; j < list.length - i - 1; j++)
			{
				if (list[j].compareToDate(list[j + 1]) > 0)
				{
					T temp = list[j];
					list[j] = list[j + 1];
					list[j + 1] = temp;
				}
			}
		}
	}
	
	/**
	 * Sorts the list by date.
	 * @param list The list to be sorted.
	 */
	public void dateSort(ArrayList<T> list)
	{
		for (int i = 0; i < list.size(); i++)
		{
			for (int j = 0; j < list.size() - i - 1; j++)
			{
				if (list.get(j).compareToDate(list.get(j + 1)) > 0)
				{
					T temp = list.get(j);
					list.set(j, list.get(j + 1));
					list.set(j + 1, temp);
				}
			}
		}
	}
	
	/**
	 * Sorts the list.
	 * @param list The list to be sorted.
	 */
	public void sort(T[] list)
	{
		for (int i = 0; i < list.length; i++)
		{
			for (int j = 0; j < list.length - i - 1; j++)
			{
				if (list[j].compareTo(list[j + 1]) > 0)
				{
					T temp = list[j];
					list[j] = list[j + 1];
					list[j + 1] = temp;
				}
			}
		}
	}
	
	/**
	 * Sorts the list.
	 * @param list The list to be sorted.
	 */
	public void sort(ArrayList<T> list)
	{
		for (int i = 0; i < list.size(); i++)
		{
			for (int j = 0; j < list.size() - i - 1; j++)
			{
				if (list.get(j).compareTo(list.get(j + 1)) > 0)
				{
					T temp = list.get(j);
					list.set(j, list.get(j + 1));
					list.set(j + 1, temp);
				}
			}
		}
	}
}
